package test;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseMoveListener;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class CursorMoveRedraw {

	/**
	 * @param args
	 */
	public static void main( String[] args ) {
		final Display display = Display.getDefault();
		final Shell shell = new Shell( display, SWT.SHELL_TRIM );
		shell.open();

		final Canvas canvas = new Canvas( shell, SWT.DOUBLE_BUFFERED );
		canvas.setBounds( 0, 0, 300, 300 );
		canvas.addPaintListener( new PaintListener() {
			@Override
			public void paintControl( PaintEvent e ) {
				e.gc.setBackground( display.getSystemColor( SWT.COLOR_BLUE ) );
				e.gc.fillRectangle( 0, 0, 300, 300 );
			}
		} );
		canvas.addMouseMoveListener( new MouseMoveListener() {
			@Override
			public void mouseMove( MouseEvent e ) {
				canvas.redraw();
			}
		} );

		while ( !shell.isDisposed() ) {
			if ( !display.readAndDispatch() ) display.sleep();
		}
		display.dispose();
	}

}
